//
//  DHAccountBaseViewController.m
//  DHKuaiYi
//
//  Created by Cedric Zheng on 15/11/2016.
//  Copyright © 2016 30-陈辉华. All rights reserved.
//

#import "DHAccountBaseViewController.h"
#import <Masonry.h>

@interface DHAccountBaseViewController ()

@end

@implementation DHAccountBaseViewController

#pragma mark - Life Cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    
    //判断当前控制器是不是第一个控制器，如果是就创建一个取消按钮
    if (self.navigationController.viewControllers[0] == self) {
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(NavigationBarCancelButtonDidTapped)];
    }
    
    /*----设置器提示效果----*/
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeGradient];

}

- (void)xhhSetupSubviews {
    [super xhhSetupSubviews];
    
    /*----设置背景图片----*/
    UIImageView *imgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pic_hd"]];
    [imgV setContentMode:UIViewContentModeScaleToFill];
    [self.view addSubview:imgV];
    
    [imgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
}

#pragma mark - Events
- (void)NavigationBarCancelButtonDidTapped {
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark – Private Methods

/**
 设置Textfield的样式

 @param imageName TextField左边的图片
 @param placehoder 占位文字
 @return 一个左边带图片，有占位文字的TextField
 */
- (UITextField *)getTextFieldWithLeftFieldImageName:(NSString *)imageName placeholder:(NSString *)placehoder {
    UITextField *textField = [[UITextField alloc] init];
    [textField setTextFieldLeftImageWithImageNamed:imageName];
    textField.placeholder = placehoder;
    textField.borderStyle = UITextBorderStyleRoundedRect;
    return textField;
}

#pragma mark - <#Delegates#>

#pragma mark - <#Datasources#>

#pragma mark – Getters and Setters

- (UITextField *)userNameTextField {
    if (!_userNameTextField) {
        UITextField *userNameTextField = [self getTextFieldWithLeftFieldImageName:@"login_phoneNumber" placeholder:@"请输入您的手机号码"];
        userNameTextField.keyboardType = UIKeyboardTypePhonePad;
        userNameTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
        
        _userNameTextField = userNameTextField;
        [self.view addSubview:userNameTextField];
    }
    return _userNameTextField;
}

- (UITextField *)passwordTextField {
    if (!_passwordTextField) {
        UITextField *passwordTextField = [self getTextFieldWithLeftFieldImageName:@"login_passWord1" placeholder:@"请输入您的密码"];
        passwordTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
        
        _passwordTextField = passwordTextField;
        [self.view addSubview:passwordTextField];
    }
    return _passwordTextField;
}

- (UIButton *)aGreenButton {
    if (!_aGreenButton) {
        UIButton *aGreenButton = [UIButton new];
        [aGreenButton setTitle:@"绿色按钮一个" forState:UIControlStateNormal];
        [aGreenButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [aGreenButton setBackgroundImage:[UIImage imageNamed:@"buttonBackground"] forState:UIControlStateNormal];
        
        _aGreenButton = aGreenButton;
        [self.view addSubview:aGreenButton];
    }
    return _aGreenButton;
}



@end
